<?php

include 'db_helper.php';


function createTile($image, $name, $width, $height, $yards, $colorID, $amountLeft) {
	
	$dbQuery = sprintf("INSERT INTO `tile` (`Image`, `Name`, `Width`, `Height`, `Yards`, `ColorID`, `AmountLeft`) VALUES ('%s', '%s', '%s', '%s', '%s', '%s', '%s');", 
		mysql_real_escape_string($image),
		mysql_real_escape_string($name),
		mysql_real_escape_string($width), 
		mysql_real_escape_string($height), 
		mysql_real_escape_string($yards),
		mysql_real_escape_string($colorID),
		mysql_real_escape_string($amountLeft));

	$result = getDBResultInserted($dbQuery, 'TileID');

	header("Content-type: application/json");
	echo json_encode($result);
	
}

function readTile($tileID) {

	$dbQuery = sprintf("SELECT * FROM `tile` WHERE `TileID`='%s';", mysql_real_escape_string($tileID));

	$result=getDBResultRecord($dbQuery);
	header("Content-type: application/json");
	echo json_encode($result);
	
}

function readAllTiles() {

	$dbQuery = sprintf("SELECT * FROM `tile`;");

	$result = getDBResultsArray($dbQuery);
	header("Content-type: application/json");
	echo json_encode($result);
	
}

function updateTile($tileID, $image, $name, $width, $height, $yards, $colorID, $amountLeft) {

	$dbQuery = sprintf("UPDATE `tile` SET `Image`='%s',`Name`='%s',`Width`='%s',`Height`='%s',`Yards`='%s',`ColorID`='%s',`AmountLeft`='%s' WHERE `TileID`='%s';", 
		mysql_real_escape_string($image),
		mysql_real_escape_string($name), 
		mysql_real_escape_string($width), 
		mysql_real_escape_string($height),
		mysql_real_escape_string($yards),
		mysql_real_escape_string($colorID),
		mysql_real_escape_string($amountLeft),
		mysql_real_escape_string($tileID));

	$result = getDBResultAffected($dbQuery);

	header("Content-type: application/json");
	echo json_encode($result);
}


function deleteTile($tileID) {

	$dbQuery = sprintf("DELETE FROM `tile` WHERE `TileID` = '%s';", mysql_real_escape_string($tileID));
	$result = getDBResultAffected($dbQuery);

	header("Content-type: application/json");
	echo json_encode($result);
	
}

/*
 * ------------------------------------------------------------------------------------------------------------------------
 * ------------------------------------------------------------------------------------------------------------------------
 * ------------------------------------------------------------------------------------------------------------------------
 */


  
 
 ?>
